//先导入fs模块
const fs = require('fs');

//自动化函数
const routerRegister = (app)=>
{
    //读取该文件夹下的所有文件
    const files = fs.readdirSync(__dirname);
    //遍历文件
    for (let i = 0; i < files.length; i++)
    {
        const file = files[i];
        if (!file.endsWith('.router.js')) continue;
        const router = require(`./${file}`);
        console.log("router:", router);
        app.use(router.routes());
        app.use(router.allowedMethods());
    }
}

module.exports = {
     routerRegister
 }